<template>
  <div class="box">
    <div class="container">
      <!-- 轮播图 -->
      <div class="banner">
        <!-- 侧边栏 -->
        <div class="nav_bar">
          <ul class="nav_list">
            <li class="nav_item" v-for="nav in navList" :key="nav.nav1Id">
              <a href=""> {{ nav.navName }} <em class="nav_arrow">&gt;</em> </a>
              <div
                class="children_list"
                :style="{ width: nav.list?.length * 248 + 'px' }"
              >
                <ul v-for="(nav2, index) in nav.list" :key="index">
                  <li v-for="(nav3, index) in nav2" :key="index">
                    <a href="">
                      <img :src="nav3.navImgUrl" />
                      {{ nav3.navName }}
                    </a>
                  </li>
                </ul>
              </div>
            </li>
          </ul>
        </div>
        <div class="block">
          <el-carousel trigger="click" height="460px">
            <el-carousel-item v-for="item in bannerList" :key="item.id">
              <img :src="item.bannerUrl" class="banner_Img" />
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
      <!-- 主体下部分 -->
      <div class="main-sub clearfixed">
        <div class="main-sub-l">
          <ul class="l-list clearfixed">
            <li v-for="(serviceItem, index) in serviceList" :key="index">
              <a href="javascript:;">
                <img :src="serviceItem.serviceImgUrl" alt="" />
                {{ serviceItem.serviceName }}
              </a>
            </li>
          </ul>
        </div>
        <div class="main-sub-r">
          <ul class="main-sub-ul">
            <li>
              <a href="javascript:;">
                <img
                  src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/d0c515086acb3c3a3e976ad20901aac5.jpg?w=632&h=340"
                  alt=""
                />
              </a>
            </li>
            <li>
              <a href="javascript:;">
                <img
                  src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/254c711cc71facf156ac955b8719dffa.jpg?w=632&h=340"
                  alt=""
                />
              </a>
            </li>
            <li>
              <a href="javascript:;">
                <img
                  src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/2b120c0dddc056dcb36e847269fb92cd.jpg?w=632&h=340"
                  alt=""
                />
              </a>
            </li>
          </ul>
        </div>
      </div>
      <!-- 广告 -->
      <div class="adv">
        <a href="javascript:;">
          <img
            src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7c23f75a5408f22960772597ad8dc792.jpg?thumb=1&w=1533&h=150&f=webp&q=90"
            alt=""
          />
        </a>
      </div>
      <div class="sale" v-for="(saleItem, index) in saleList" :key="index">
        <div class="adv" v-if="index === saleList.length - 1">
          <a href="javascript:;">
            <img
              src="https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/88e35cffc82cd98cd53172460067af17.jpg?thumb=1&w=1533&h=150&f=webp&q=90"
              alt=""
            />
          </a>
        </div>

        <div class="sale_content">
          <h3>{{ saleItem.title }}</h3>
          <ul class="sale_tab">
            <li v-for="(item, index) in saleItem.classList" :key="index">
              <p v-if="item.saleClassName" :class="{ active: index === 0 }">
                {{ item.saleClassName }}
              </p>
              <div class="see_more" @click="toSeeMore(index)" v-else>
                查看更多<i class="iconfont icon-youjiantou1"></i>
              </div>
              <div
                class="sale_body"
                :style="{ zIndex: index === 0 ? '2' : '1' }"
              >
                <div class="sale_left">
                  <ul>
                    <li
                      v-for="(leftItem, index) in item.saleClassLeftList"
                      :key="index"
                      class="shadow"
                    >
                      <img :src="leftItem.saleImgUrl" />
                    </li>
                  </ul>
                </div>
                <div class="sale_right">
                  <ul>
                    <li
                      v-for="(rightItem, index) in item.saleClassRightList"
                      :class="{ last_item: !rightItem.saleDetail }"
                      :key="index"
                    >
                      <div v-if="!rightItem.saleDetail">
                        <a href="" class="shadow">
                          <div class="last_item_left">
                            <div class="sale_title">
                              {{ rightItem.saleName }}
                            </div>
                            <div class="sale_price">
                              {{ rightItem.salePrice }}元起
                            </div>
                          </div>
                          <img
                            class="sale_img"
                            :src="rightItem.saleImgUrl"
                            alt=""
                          />
                        </a>
                        <a href="" class="shadow">
                          <div class="last_item_left more">
                            <div>浏览更多</div>
                            <div class="small">穿戴</div>
                          </div>
                          <i class="iconfont icon-youjiantou right_arrow" />
                        </a>
                      </div>
                      <div v-else>
                        <a href="" class="shadow">
                          <img
                            class="sale_img"
                            :src="rightItem.saleImgUrl"
                            alt=""
                          />
                          <div class="sale_title">{{ rightItem.saleName }}</div>
                          <div class="sale_detail">
                            {{ rightItem.saleDetail }}
                          </div>
                          <div class="sale_price">
                            {{ rightItem.salePrice }}元起
                            <s v-if="rightItem.originPrice" class="del">
                              {{ rightItem.originPrice }}元
                            </s>
                          </div>
                        </a>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getNavList,
  getBannerList,
  getSaleList,
  getServiceList,
} from "@/api/home";
export default {
  name: "MiHome",
  data() {
    return {
      navList: [],
      bannerList: {},
      saleList: [],
      serviceList: [],
    };
  },
  methods: {
    toSeeMore(index) {
      this.$router.push({
        name: "phone",
        query: {
          keyId: index,
        },
      });
    },
  },
  async mounted() {
    this.navList = await getNavList();
    this.bannerList = await getBannerList();
    this.saleList = await getSaleList();
    this.serviceList = await getServiceList();
  },
  watch: {
    saleList: {
      handler() {
        this.$nextTick(() => {
          const liNodes = document.querySelectorAll(".sale_tab>li>p");
          for (let i = 0; i < liNodes.length; i++) {
            liNodes[i].addEventListener("mouseenter", function () {
              const brotherBody =
                this.parentNode.parentNode.querySelectorAll(".sale_body");
              const brotherTab =
                this.parentNode.parentNode.querySelectorAll("p");
              for (let j = 0; j < brotherBody.length; j++) {
                brotherBody[j].style.zIndex = 0;
                brotherTab[j].className = "";
              }
              this.className = "active";
              const currentBody = this.parentNode.querySelector(".sale_body");
              currentBody.style.zIndex = 2;
            });
          }
        });
      },
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  background-color: #f5f5f5;
}
.container {
  width: 1226px;
  margin: 0px auto;
}
.banner {
  position: relative;
  height: 460px;
  background-color: gray;
  .nav_bar {
    position: absolute;
    left: 0;
    z-index: 3;
    padding: 20px 0px;
    height: 420px;
    width: 234px;
    background-color: rgba(105, 101, 101, 0.6);
    .nav_item {
      height: 42px;
      line-height: 42px;
      padding-left: 30px;
    }
    .nav_item:hover {
      background-color: #ff6700;
    }
    .nav_item:hover .children_list {
      display: block;
    }
    .nav_item a {
      text-decoration: none;
      display: block;
      position: relative;
      font-size: 13px;
      color: #fff;
    }
    .nav_arrow {
      position: absolute;
      top: 12px;
      right: 20px;
      font-size: 16px;
      line-height: 16px;
      color: #e0e0e0;
    }
    .children_list {
      overflow: hidden;
      position: absolute;
      display: none;
      padding: 1px 0px;
      left: 234px;
      top: 0;
      height: 458px;
      border-left: 0;
      background: #fff;
      box-shadow: 0 8px 16px rgb(0 0 0 / 18%);
      ul {
        width: 248px;
        float: left;
        li {
          a {
            display: block;
            width: 225px;
            height: 40px;
            padding: 18px 13px;
            line-height: 40px;
            color: #333;
            img {
              margin-right: 12px;
              vertical-align: middle;
            }
          }
        }
      }
    }
  }
  :deep(.el-carousel__indicators--horizontal) {
    left: 95%;
    bottom: 10px;
    opacity: 0.6;
  }
  :deep(.el-carousel__button) {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    border: 2px solid #ccc;
    background: rgba(0, 0, 0, 0.4);
    opacity: 1;
  }
  .el-carousel__item .banner_Img {
    height: 100%;
  }
  :deep(.el-carousel__arrow) {
    border-radius: 0%;
    height: 67px;
    font-size: 30px;
    color: #ccc;
    background-color: transparent;
  }
  :deep(.el-carousel__arrow--left) {
    left: 234px;
  }
  :deep(.el-carousel__arrow--left:hover) {
    color: #fff;
    background-color: rgba(127, 127, 127, 0.4);
  }
  :deep(.el-carousel__arrow--right) {
    right: 0px;
  }
  :deep(.el-carousel__arrow--right:hover) {
    color: #fff;
    background-color: rgba(127, 127, 127, 0.4);
  }
  :deep(.el-carousel__indicator.is-active button) {
    background-color: #ccc;
  }
}
//主体下半部分
.main-sub {
  height: 170px;
  margin-top: 14px;
  margin-bottom: 26px;
  //下半部分左侧
  .main-sub-l {
    float: left;
    width: 234px;
    .l-list {
      height: 164px;
      background-color: #5f5750;
      padding: 3px;
      li {
        float: left;
        width: 70px;
        height: 82px;
        padding: 0 3px;
        font-size: 12px;
        a {
          position: relative;
          display: flex;
          width: 100%;
          height: 100%;
          color: #fff;
          opacity: 0.7;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          opacity: 0.7;
          transition: all 0.3s;
          img {
            display: block;
            width: 24px;
            height: 24px;
            margin-bottom: 4px;
          }
          &::after {
            position: absolute;
            right: 0;
            top: 6px;
            width: 1px;
            height: 70px;
            background-color: #706963;
            content: "";
          }
          &:hover {
            opacity: 1;
          }
        }
        &:nth-child(3n) a {
          &::after {
            width: 0;
          }
        }
        &:nth-child(n + 3) a {
          &::before {
            position: absolute;
            left: -2px;
            top: 0;
            width: 64px;
            height: 1px;
            background-color: #706963;
            content: "";
          }
        }
      }
    }
  }
  //下半部分右侧
  .main-sub-r {
    float: left;
    width: 992px;
    .main-sub-ul {
      li {
        float: left;
        margin-left: 15px;
        a {
          display: block;
          width: 316px;
          height: 170px;
          img {
            width: 100%;
            height: 100%;
            margin: 0;
          }
        }
        &:first-child {
          margin-left: 14px;
        }
        &:hover {
          box-shadow: 0 15px 30px rgb(0 0 0 / 10%);
          transition: box-shadow 0.2s linear;
        }
      }
    }
  }
}

.adv img {
  margin: 22px 0px;
  width: 100%;
}

.sale {
  .sale_content {
    overflow: hidden;
    height: 686px;
    position: relative;
    h3 {
      float: left;
      margin: 0;
      height: 70px;
      font-size: 22px;
      font-weight: 200;
      line-height: 58px;
      color: #333;
    }
    .sale_tab {
      height: 58px;
      float: right;
      li {
        float: left;
        p {
          font-size: 14px;
          margin: 20px 0px 0px 20px;
          padding: 5px 0px;
          transition: all 0.5s;
          cursor: pointer;
          &.active {
            color: #ff6700;
            border-bottom: 2px solid #ff6700;
          }
        }
        .see_more {
          height: 58px;
          line-height: 58px;
          font-size: 16px;
          color: #424242;
          transition: all 0.4s;
          cursor: pointer;
          i {
            margin-left: 5px;
            vertical-align: middle;
            font-size: 25px;
            color: #b0b0b0;
          }
          &:hover {
            color: #ff6700;
            i {
              color: #ff6700;
            }
          }
        }
      }
    }
    .sale_body {
      position: absolute;
      top: 60px;
      left: 0;
      display: flex;
      height: 614px;
      .shadow {
        transition: all 0.2s linear;
        &:hover {
          z-index: 2;
          box-shadow: 0 15px 30px rgb(0 0 0 / 10%);
          transform: translate3d(0, -2px, 0);
        }
      }
      .sale_left {
        width: 234px;
        height: 614px;
        li {
          margin-bottom: 14px;
          img {
            width: 100%;
            height: 100%;
            vertical-align: top;
          }
        }
      }
      .sale_right {
        width: 992px;
        height: 614px;
        ul {
          width: 992px;
          height: 614px;
          li {
            float: left;
            margin: 0px 0px 14px 14px;
            height: 300px;
            width: 234px;
            a {
              display: flex;
              flex-direction: column;
              align-items: center;
              height: 260px;
              width: 234px;
              padding: 20px 0px;
              font-weight: 400;
              background-color: #fff;

              .sale_img {
                width: 160px;
                height: 160px;
                margin-bottom: 18px;
              }
              .sale_title {
                font-size: 14px;
                color: #333;
              }
              .sale_detail {
                width: 214px;
                text-align: center;
                margin: 2px 10px 10px;
                font-size: 2px;
                color: #b0b0b0;
                text-overflow: ellipsis;
                white-space: nowrap;
                overflow: hidden;
              }
              .sale_price {
                font-size: 13px;
                color: #ff6700;
                .del {
                  margin-left: 5px;
                  font-size: 12px;
                  color: #b0b0b0;
                }
              }
            }
          }
          .last_item {
            a {
              flex-direction: row;
              align-items: flex-start;
              width: 204px;
              padding: 40px 0px 10px 30px;
              height: 93px;
              margin-bottom: 14px;
              font-size: 14px;
              img {
                height: 80px;
                width: 80px;
              }
              .sale_title {
                margin: 0px 0px 5px;
                width: 94px;
                height: 42px;
                word-wrap: break-word;
              }
            }
            .more {
              margin-right: 20px;
              color: #333;
              font-size: 18px;
              .small {
                margin-top: 5px;
                font-size: 12px;
                color: #757575;
              }
            }
            .right_arrow {
              margin-top: -7px;
              margin-left: 19px;
              font-size: 48px;
              color: #ff6700;
            }
          }
        }
      }
    }
  }
}
:deep(.el-tabs__nav-wrap) {
  overflow: visible;
}
:deep(.el-tabs__header) {
  margin: 0;
}
:deep(.el-tabs__nav-scroll) {
  position: absolute;
  height: 40px;
  top: -50px;
  right: 0;
}
:deep(.el-tabs__nav-wrap::after) {
  background-color: transparent;
}
:deep(.el-tabs__item.is-active) {
  border-bottom: 3px solid #ff6700 !important;
  color: #ff6700;
}
:deep(.el-tabs__active-bar) {
  background-color: #ff6700;
}
:deep(.el-tabs__item:hover) {
  color: #ff6700;
}
:deep(.el-tabs--card > .el-tabs__header .el-tabs__nav) {
  border-color: transparent;
}
:deep(.el-tabs--card > .el-tabs__header .el-tabs__item) {
  border-color: transparent;
}
:deep(.el-tabs--card > .el-tabs__header) {
  border: none;
}
</style>
